<?php
if ($contact_information -> num_rows() > 0) {
	foreach ($contact_information->result() as $row) {
		$use_country_id = $country_id_selected;
		$use_location_id = $row -> use_location_id;
		$fax = $row -> fax;
		$address = $row -> address;
		
	}
} else {
	
	$use_country_id = "";
	$use_location_id = "";
	$fax = "";
	$address = "";
}
?>

<div class="login">
          <div class="wrap">
				<ul class="breadcrumb breadcrumb__t"><a class="home" href="<?php echo base_url(); ?>">Home</a>  / You are logged in as <?php echo $this -> mod_account -> get_logged_in_user_info() -> email; ?> </ul>
				<div class="section group">
					<?php $this -> load -> view(F_MASTER . "dashboard_account"); ?>
				   
				    <div class="cont span_2_of_about">
				    	
				    		<!--<div class="alert alert-error"><?php echo validation_errors(); ?></div>-->
					
				
	           		<h3>User Contact Information</h3>
	           		<form class="form-horizontal" method="post" action="<?php echo base_url(); ?>account/contact">	
		<div class="row">
                <div class="col-lg-12">
                	<?php
					//$this->load->view('help/notifications');
                    ?>
                    <div class="panel panel-primary">
                        <div class="panel-heading">
                          Contact information
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body form-horizontal">
							
							<!-- Text input-->
							<div class="form-group">
								<label class="col-md-4 control-label" for="country">Country <span style="color: red;">*</span></label>
								<div class="col-md-6">
									<select name="country" class="form-control" id="country">
										<option value=" ">--Select Country--</option>
										<?php
											foreach($countries->result() as $country){
												$country_id=$country->country_id;
												$country_name=$country->name;
												if($country_id==$use_country_id){
										?>
												<option value="<?php echo $country_id; ?>" selected="selected"><?php echo $country_name; ?></option>
										<?php	}else{
										?>
												<option value="<?php echo $country_id; ?>"><?php echo $country_name; ?></option>
										<?php		
												}
										
										}
										?>
										
									</select>
									<span class="help-block"><?php echo form_error('country'); ?></span>
								</div>
							</div>
							
							<!-- Text input-->
							<div class="form-group">
								<label class="col-md-4 control-label" for="location">Location <span style="color: red;">*</span></label>
								<div class="col-md-6">
									<select name="location" class="form-control" id="location">
										
										<?php
											if($location_id_selected!=0){
												foreach($locations->result() as $location){
													$location_id=$location->location_id;
													$location_name=$location->name;
													if($use_location_id==$location_id){
										?>
														<option value="<?php echo $location_id;?>" selected="selected"><?php echo $location_name;?></option>
										<?php
													}else{
										?>
														<option value="<?php echo $location_id;?>"><?php echo $location_name;?></option>
										<?php
													}
										?>
													
										<?php
												}
											}else{
												echo '<option value="0">--Select Location--</option>';
											}
										?>
									</select>
									<span class="help-block"><?php echo form_error('location'); ?></span>
								</div>
							</div>
							
							<!-- Text input-->
							<div class="form-group">
								<label class="col-md-4 control-label" for="fax">Fax</label>
								<div class="col-md-6">
									<input id="fax" name="fax" placeholder="" class="form-control input-md" type="text" value="<?php echo $fax; ?>">
									<span class="help-block"><?php echo form_error('fax'); ?></span>
								</div>
							</div>
							
							<!-- Text input-->
							<div class="form-group">
								<label class="col-md-4 control-label" for="address">Address</label>
								<div class="col-md-8">
									<textarea class="form-control" rows="10" name="address"><?php echo $address; ?></textarea>
									<span class="help-block"><?php echo form_error('address'); ?></span>
								</div>
							</div>
							
							<!-- Text input-->
							<div class="form-group">
								<label class="col-md-4 control-label" for="phones">Phone <span style="color: red;">*</span></label>
								<div class="col-md-6">
									
										<?php
											if($phones->num_rows()>0){
												$num_row=$phones->num_rows();
											$i=0;
												foreach($phones->result() as $phone){
													$phone_id=$phone->product_owner_phone_id;
													$phone_number=$phone->phone_number;
													if($i==($num_row-1)){
														$class_btn="btn btn-default btn-add";
														$symbol="+";
													}else{
														$class_btn="btn btn-danger btn-remove";
														$symbol="-";
													}
											?>
											<div class="form-group input-group">
											    <input id="job_see_con_pho_phone" name="phones[]" placeholder="" class="form-control input-md" required="required" type="text" value="<?php echo $phone_number;?>">
											    <span class="input-group-btn"><button type="button" class="<?php echo $class_btn;?>"><?php echo $symbol;?></button></span>
										    </div>
										    <?php
										    		$i++;
												}
										
									     	
											}else{
										?>
											<div class="form-group input-group">
												<input id="job_see_con_pho_phone" name="phones[]" placeholder="" class="form-control input-md" required="required" type="text" value="<?php echo set_value('job_see_con_pho_phone'); ?>">
										   		<span class="input-group-btn"><button type="button" class="btn btn-default btn-add">+</button></span>
										   </div>
										<?php
											}
										?>	
								    
								    
								</div>
							</div>
											
                         </div>
                    </div>
                </div>
           </div>
           
           
           
           <div class="row"><!-- Button (Double) -->
							
                <div class="col-lg-12">
                    	<div class="form-group">
								<label class="col-md-4 control-label" for="submit"></label>
								<div class="col-md-8">
									<button id="submit" name="submit" class="btn btn-success" type="submit">
										<i class="glyphicon glyphicon-ok"></i>
										<?php echo $this -> lang -> line('button_save'); ?>
									</button>
									<button id="clear" name="clear" class="btn btn-warning" type="button" onclick="goBack()">
										<i class="glyphicon glyphicon-remove"></i>
										<?php echo $this -> lang -> line('button_cancel'); ?>
									</button>
								</div>
							</div>
                </div>
                <!-- /.col-lg-12 -->
            </div>
</form>                   	
			    
				
				<div class="clear"></div>
			
					</div>
           </div>
		   <div class="clear"></div>	
		  </div>
	</div>	
   



<script type="text/javascript">
            	$(document).ready(function() {

                $('#country').change(function() {

                    // assign the value to a variable, so you can test to see if it is working
                    var selectVal = $('#country :selected').val();

                    $.post("<?php echo base_url(); ?>account/get_location_by_country",
	{
	country_id: selectVal
	},
	function(data, status) {

	$("#location").empty();
	$("#location").append(data);

	});
	});

	});
        </script>

